const app = getApp();
let tool = require('../../utils/tool.js');
let utils = require('../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        /**
         * 页面配置
         */
        winWidth: 0,
        winHeight: 0,
        // tab切换
        currentTab: 0,
        imageurl: app.globalData.imageurl,
        list0: {},
        list1: {},
        list2: {},
        tjhidden:true,
        bghidden:true

    },
    getData: function () {
        let that = this;
        let paramArr = {
            access_token: app.globalData.studentInfo.access_token?app.globalData.studentInfo.access_token:app.globalData.access_token,
            type: this.data.currentTab + 1
        }
        let rs = tool.getSign(paramArr, app.globalData.key); //返回 bodyParam heaer sign
        let sign = rs.sign;
        let apiUrl = app.globalData.apiURL + "message/lists?sign=" + sign;
        let classPro = new Promise(
            function (resolve, reject) {
                wx.request({
                    url: apiUrl,
                    header: rs.header,
                    data: rs.bodyParam,
                    method: 'post',
                    success(res) {
                        resolve(res);
                    }
                })
            }
        );

        let classHis = new Object();
        classPro.then(function (res) {
            if (res.data.code === 1) {
                classHis = res.data;
                let typeName = 'list' + that.data.currentTab;
                that.setData({
                    [typeName]: res.data.data.list
                    //     confirmed: classHis.data.confirmed,
                    //     confirmles: classHis.data.confirmles,
                    //     justsub: classHis.data.rowfirm
                });
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;

        /**
         * 获取系统信息
         */
        wx.getSystemInfo({

            success: function (res) {
                that.setData({
                    winWidth: res.windowWidth,
                    winHeight: res.windowHeight
                });
            }

        });
        this.getData();
    },
    /**
     * 滑动切换tab
     */
    bindChange: function (e) {

        var that = this;
        that.setData({currentTab: e.detail.current});
        that.getData();
    },
    /**
     * 点击tab切换
     */
    swichNav: function (e) {

        var that = this;

        if (this.data.currentTab === e.target.dataset.current) {
            return false;
        } else {
            that.setData({
                currentTab: e.target.dataset.current
            });
            that.getData();
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    gotourl: function (e) {
        let ids = e.currentTarget.dataset.id;
        if (this.data.list0[ids].type == 5) {
            wx.navigateTo({
                url: './noticeCard/noticeCard?data=' + this.data.list0[ids].content,
            });
        } else {
            wx.showToast({
                title: this.data.list0[ids].content,
                icon: 'none',
                duration: 2000
            })
        }

    },
    /**
     * 点击通知下面报告的各条目，跳转报告详情界面
     */
    gotourl2: function (e) {
        let ids = e.currentTarget.dataset.id;
        var temURl = {
            '6': "../listenWorld/lworldReport/lworldReport",
            '7': "./readreport/report",
            "9": "./langdu/report",
            "10": "./tinghoujilu/report",
            "11": "./tinghouhuida/report",
            "8": "./tinghouxuanze/report",
            "13": "./cepingreport/cepingreport",
            "14": "./testresult/testresult",
        }

        if (temURl[this.data.list1[ids].type] != undefined) {
            if(this.data.list1[ids].type==6){
                console.log(temURl[this.data.list1[ids].type] + '?type=6&id=' + this.data.list1[ids].content);
                wx.navigateTo({
                    url: temURl[this.data.list1[ids].type] + '?type=6&id=' + this.data.list1[ids].content,
                });
            }else{
                wx.navigateTo({
                    url: temURl[this.data.list1[ids].type] + '?id=' + this.data.list1[ids].content,
                });
            }

        }else{
            wx.showToast({
                title: 'type='+this.data.list1[ids].type+'没有相关报告',
                icon: 'none',
                duration: 2000
            })
        }


    },
    gotourl3: function (e) {
        let ids = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: './startstastic/report?id=' + this.data.list2[ids].content,
        });
    }
})
